package com.onec.service.customer.entity.merchant;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.dto.request.gateway.BizContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 代理商:代理业务：
 *
 * @author ONEC
 */
@Data
@Entity
@Table(name = "t_merchant_business")
public class MerchantBusiness implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    private Integer version;

    /**
     * 业务编号
     */
    @Column(name = "business_no", length = 16)
    private String businessNo;

    @Column(name = "product", length = 8)
    @Enumerated(EnumType.STRING)
    private ProductEnum product;
    /**
     * 机构编号
     */
    @Column(name = "merchant_id", length = 16)
    private Long merchantId;
    /**
     * 机构编号
     */
    @Column(name = "merchant_rate", length = 16, scale = 4)
    private BigDecimal merchantRate;
    /**
     * 机构编号
     */
    @Column(name = "merchant_fee", length = 16, scale = 2)
    private BigDecimal merchantFee;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;
    /**
     * 变更
     */
    @Column(name = "update_time")
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date updateTime;
    /**
     * 创建者
     */
    @Column(name = "creator", length = 32)
    private String creator;
    /**
     * 产品备注
     */
    @Column(name = "remarks", length = 64)
    private String remarks;
    /**
     * 通道状态
     */
    @Column(name = "status", length = 12)
    @Enumerated(EnumType.STRING)
    private StatusEnum status;


    public MerchantBusiness() {
    }


    public MerchantBusiness(BizContent bizContent) {

        this.businessNo = bizContent.getBusinessNo();
        //this.product = ProductEnum.valueOf(bizContent.getProduct());
        this.merchantRate = new BigDecimal(bizContent.getRate());
        this.merchantFee = new BigDecimal(bizContent.getFee());
        this.createTime = DateUtil.date();
        this.updateTime = DateUtil.date();
        this.status = StatusEnum.SUCCESS;
    }


}
